import 'package:chat/pages/chat_detail_page.dart';
import 'package:flutter/material.dart';

class ChatUserListItem extends StatefulWidget {
  final String nickname;
  final String lastMessage;
  final String imgUrl;
  final String time;
  final bool isMessageRead;
  const ChatUserListItem(
      {Key? key, 
      required this.nickname,
      required this.lastMessage,
      required this.imgUrl,
      required this.time,
      required this.isMessageRead}) : super(key: key);
  @override
  State<ChatUserListItem> createState() => _ChatUserListItemState();
}

class _ChatUserListItemState extends State<ChatUserListItem> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        GestureDetector(
          onTap: () => Navigator.of(context)
              .push(MaterialPageRoute(builder: (context) => const ChatDetailPage())),
          child: Row(
            children: [
              Expanded(
                child: Row(
                  children: [
                    CircleAvatar(
                      backgroundImage: AssetImage(widget.imgUrl),
                      maxRadius: 30,
                    ),
                    const SizedBox(
                      width: 16,
                    ),
                    Expanded(
                        child: Container(
                            color: Colors.transparent,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(widget.nickname),
                                const SizedBox(
                                  height: 2,
                                ),
                                Text(widget.lastMessage,
                                    style: TextStyle(
                                        fontSize: 14, color: Colors.grey.shade500)),
                              ],
                            )))
                  ],
                ),
              ),
              Text(widget.time, style:TextStyle(fontSize: 12, color: widget.isMessageRead? Colors.pink:Colors.grey.shade500))
            ],
          ),
        ),
                const SizedBox(height: 16,),
      ],
    );
  }
}
